﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using pttk_htt_hr.DAO;
using pttk_htt_hr.Constant;
using pttk_htt_hr.DTO;
using pttk_htt_hr.Utility;

namespace pttk_htt_hr.GUI
{
    public partial class MH_ThemThucDon : Form
    {
        #region Fields
        public event EventHandler SubmitClicked;

        List<Dictionary<string,string>> ExtractedData;

        public List<Dictionary<string, string>> ExtractedDatas
        {
            get { return ExtractedData;}
            set{ExtractedData = value;} 
        }
        #endregion

        #region Initial
        public MH_ThemThucDon()
        {
            InitializeComponent();
        }
        #endregion

        #region Method
        void search()
        {
            // Prepare parameters
            List<SqlParameter> Parameters = new List<SqlParameter>();
            SqlParameter MaTD = new SqlParameter(ParameterConstant.MaTD, txtMaTD.Text);
            SqlParameter TenTD = new SqlParameter(ParameterConstant.TenTD, txtTenTD.Text);
            Parameters.Add(MaTD);
            Parameters.Add(TenTD);

            // List of ThucDon
            List<Dictionary<string, string>> LstDic = ThucDonBUS.Get_List(Parameters, true);

            // Add DataSource to gridview
            DataGridUtil.AddData_To_DataGridView(LstDic, dataGridView1, true, DataGridUtil.GetAll_ColumnName_DataGridView(dataGridView1).ToArray());
        }

        void add_thucdon()
        {
            string[] ArrHeaderName = new string[] { TableColumnMapping.MaTD, TableColumnMapping.TenTD };

            // Get data from grid view
            ExtractedData = DataGridUtil.ExtractDataFromDataGridViewRowSelected_LstDic(dataGridView1, ArrHeaderName, "CheckBoxCell");

            // Fire event
            SubmitClicked(this, new EventArgs());

            this.Close();
        }
        #endregion

        #region Handle Events
        private void ThucDonTim_Click(object sender, EventArgs e)
        {
            search();            
        }

        private void ThucDonThem_Click(object sender, EventArgs e)
        {
            add_thucdon();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion


    }
}
